<?php

namespace App\Http\Controllers\Admin\UserManager;

use App\Exceptions\BasicException;
use App\Http\Controllers\BaseController;
use Illuminate\Http\Request;    //引用http请求类
use App\Response\Response;

class FeedBackController extends BaseController {


    /**
     * @api {delete} /user-manager/feed-back 意见反馈-删除
     * @apiVersion 0.1.0
     * @apiName 会员管理-意见反馈-删除
     * @apiGroup 会员管理
     *
     * @apiParam {string} ids                       字符串分割的id 必传
     *
     * @apiSuccessExample 成功响应
     *
     *      {"code":200,"data":true}
     *
     * @apiError 10001 参数校验失败
     *
     * @apiErrorExample 错误响应
     *
     *      {
     *          "code": 10001,
     *          "message": "errorMsg"
     *      }
     *
     */
    public function del(Request $request) {
        //参数校验
        try {
            $this->validate($request, [
                'ids' => 'required|string',
            ]);

        } catch (\Exception $e) {
            throw new BasicException(10001, json_encode($e->errors()));
        }

        $idsStr = $request->input("ids");
        $idsArr = explode("," , $idsStr);

        $rows = app('repo_user')->delFeedBack($idsArr);
        if (!$rows) {
            throw new BasicException(10001, "删除失败！");
        }

        return Response::sendData(true);
    }


    /**
     * @api {get} /user-manager/feed-back 意见反馈-列表
     * @apiVersion 0.1.0
     * @apiName 会员管理-意见反馈-列表
     * @apiGroup 会员管理
     *
     * @apiParam {number} page 当前页数 可选
     * @apiParam {number} perPage 分页容量 可选
     *
     *
     * @apiSuccessExample 成功响应
     *
     *
    {
    "code": 200,
    "data": {
        "list": [
            {
                "comment(反馈内容)": "一次",
                "create_time(反馈时间)": "2020-11-02 14:25:21",
                "nickname(昵称)": "杭州蔡徐坤",
                "user_code(用户编号)": 111111,
                "head_picture(头像)": "https://yutangyuyin.oss-cn-hangzhou.aliyuncs.com/ios_images/2020-11-03/CE5635F2-F3E7-4538-97FE-2B20E166D884.jpeg",
                "mobile(电话)": "15538278963"
            }
        ],
        "meta": {
                "page": 1,
                "limit": 10,
                "next": null,
                "total": 1
            }
        }
     }
     *
     *
     */
    public function list(Request $request) {
        //参数校验
        try {
            $this->validate($request, [
                'perPage' => 'filled|numeric',
                'page' => 'filled|numeric',
            ]);
        } catch (\Exception $e) {
            throw new BasicException(10001, json_encode($e->errors()));
        }

        $list = app('repo_user')->getFeedBackQueryList($request->input());

        return Response::sendList($list);
    }


}
